package com.diyphonegadgets.robot;

import android.app.Activity;
import android.content.SharedPreferences;
import android.content.SharedPreferences.Editor;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView.BufferType;

public class Properties extends Activity {

	public static final String CAMPREFS = "camprefs";
	OnClickListener saveButtonListener;
	Button saveButton;
	SharedPreferences sp;
	EditText et1,et2, et3, et4, et5;
	

	@Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);      
        setContentView(R.layout.properties);
        
        et1 = (EditText) findViewById(R.id.EditText01);
        et2 = (EditText) findViewById(R.id.EditText02);
        et3 = (EditText) findViewById(R.id.EditText03);
        et4 = (EditText) findViewById(R.id.EditText04);
        et5 = (EditText) findViewById(R.id.EditText05);
        
        sp = getSharedPreferences(CAMPREFS, MODE_PRIVATE);
        et1.setText(sp.getString("destination ip", "192.168.43.209"), BufferType.EDITABLE);
        et2.setText(sp.getString("data sending port", "5550"), BufferType.EDITABLE);
        et3.setText(sp.getString("data receiving port", "5551"), BufferType.EDITABLE);
        et4.setText(sp.getString("camera view streaming port", "8123"), BufferType.EDITABLE);
        et5.setText(sp.getString("video streaming quality", "20"), BufferType.EDITABLE);

           
        saveButtonListener = new OnClickListener(){
        	public void onClick(View v){
        		Editor editor = sp.edit();
        		editor.putString("destination ip",et1.getText().toString());
        		editor.putString("data sending port",et2.getText().toString());
        		editor.putString("data receiving port",et3.getText().toString());
        		editor.putString("camera view streaming port",et4.getText().toString());
        		editor.putString("video streaming quality",et5.getText().toString());
        		
        		editor.commit();
        		finish();
        	}
        };
        saveButton = (Button) findViewById(R.id.Button02);
        saveButton.setOnClickListener(saveButtonListener);
		
    }
	
}
